﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using Microsoft.Win32;
using KnowWare.Model;


namespace KnowWareBeta
{
    /// <summary>
    /// Interaction logic for IndlæsWindow.xaml
    /// </summary>
    public partial class IndlæsWindow : Window
    {
        string holdFil;
        string kategoriFil;
        MainWindow _parent;

        public IndlæsWindow(MainWindow parent)
        {
            _parent = parent;
            InitializeComponent();
        }

        private void btn_indlæsHold_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "CSV Fil (.csv)|*.csv";
            ofd.FilterIndex = 0;
            ofd.Multiselect = false;

            bool? status = ofd.ShowDialog();
            if (status == true)
            {
                holdFil = ofd.FileName;
                lbl_hold.Content = System.IO.Path.GetFileName(ofd.FileName);
            }
            
        }

        private void btn_indlæsKategorier_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "CSV Fil (.csv)|*.csv";
            ofd.FilterIndex = 0;
            ofd.Multiselect = false;

            bool? status = ofd.ShowDialog();
            if (status == true)
            {
                kategoriFil = ofd.FileName;
                lbl_kategorier.Content = System.IO.Path.GetFileName(ofd.FileName);
            }
        }

        private bool ValiderFormular()
        {
            if (tB_navn.Text == "" || !datePicker1.SelectedDate.HasValue || holdFil == null || kategoriFil == null || (holdFil == kategoriFil && holdFil != null && kategoriFil != null)) return false;
            return true;
        }

        private void btn_startEvent_Click(object sender, RoutedEventArgs e)
        {
            if (ValiderFormular())
            {
                Event nytEvent = new Event(tB_navn.Text, datePicker1.SelectedDate.Value, holdFil, kategoriFil);
                new HovedWindow(nytEvent).Show();
                _parent.Close();
                this.Close();
            }
            else
            {
                if (holdFil == kategoriFil && holdFil != null && kategoriFil != null)
                {
                    MessageBox.Show("Vælg venligst to forskellige filer");
                }
                else
                {
                    MessageBox.Show("Udfyld venligst alle felter");
                }
            }
        }
    }
}
